package com.base.study.presenter;

import android.app.Activity;

import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;
import com.base.study.bean.SubjectListBean;
import com.base.study.bean.SubjectResoutEntity;
import com.base.study.view.SubjectView;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.disposables.Disposable;

/**
 * Created by weikailiang on 2020/3/8.
 */

public class SubjectPresenter extends BasePresenter<SubjectView>{
    public SubjectPresenter(SubjectView view, Activity activity) {
        super(view, activity);
    }

    public void getList(final Integer page, Integer limit){
        mView.showPb();
        Map<String, Object> map = new HashMap<>();
        map.put("keyWord","");
        map.put("limit", limit);
        map.put("limitControlflg","1");
        map.put("page",page);
        map.put("ruleControlflg", "0");
        map.put("searchRuleId", "1fabadacac724f6bb62dc692f83b6d8c");
        Disposable enqueue = RealNetWorkUtil.postContent().method("api-searchcommon/searchMethod/useMethod").content(map)
                .build().enqueue(SubjectResoutEntity.class, new CallBackImpl<SubjectResoutEntity>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb();
                        mView.showError();
                        mView.returnError();
                    }

                    @Override
                    public void onNext(SubjectResoutEntity list) {
                        mView.hidePb();
                        if (page==1){
                            //刷新
                            if (list!=null &&list.getRows() != null&&list.getRows().size()>0){
                                mView.returnList(list);
                            }else {
                                mView.returnNoData();
                            }
                        }else {
                            //更多
                            if (list!=null &&list.getRows() != null&&list.getRows().size()>0){
                                mView.returnMoreList(list);
                            }else {
                                mView.returnNoMoreData();
                            }
                        }
                    }
                });

        mCompositeDisposable.add(enqueue);
    }
}
